package com.ynkbny.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.ynkbny.domain.pojo.TreeProjDeviceVO;
import com.ynkbny.service.DeviceService;
import com.ynkbny.util.Res;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author YY
 * @Date 2023/7/28 10:21
 */
@Slf4j
@RestController
@RequestMapping("/device")
@Api(tags = "老狗设备操作")
public class DeviceController {

    @Resource
    private DeviceService deviceService;

    /**
     * 构建设备树结构
     *
     * @Author YY
     * @param projId 项目id
     * @return JSONObject对象
     */
    @PostMapping("/build/{projId}")
    @ApiOperation("构建设备树")
    Res<JSONObject> buildDeviceTree( @PathVariable("projId") long projId){
        log.info("请求参数：{}",projId);
        JSONObject deviceTree = deviceService.buildDeviceTree(projId);
        log.info("返回值：{}",deviceTree);
        return Res.ok(deviceTree);
    }

    /**
     * 构建设备树结构
     *
     * @Author juzipi123
     * @param projId 项目id
     * @return JSONObject对象
     */
    @GetMapping("/treeProjDevice")
    @ApiOperation("构建设备树")
    Res<TreeProjDeviceVO> treeProjDevice(String projId){
        log.info("请求参数：{}",projId);
        TreeProjDeviceVO deviceTree = deviceService.treeProjDevice(projId);
        log.info("返回值：{}",deviceTree);
        return Res.ok(deviceTree);
    }
}
